<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			// 深拷贝
			
			function clong (oldObj) {
				if (oldObj === null) return oldObj
				if (typeof oldObj !== 'object') return oldObj
				var newObj = Array.isArray(oldObj) ? [] : {}
				for (var key in oldObj) {
					newObj[key] = clong(oldObj[key])
				}
				return newObj
			}	
			var arr1 = { name: 'lilei', age: 11, gender: '男', method: { son: '类似', eat: function () { console.log('eat') } } }
			var arr2 = clong (arr1)
			console.log('arr1改前',arr1)
			console.log('arr2改前', arr2)
			arr1.name = 'hanmeimei'
			arr1.method.son = 'hanmeimei'
			console.log('arr1改后', arr1)
			console.log('arr2改后', arr2)
		</script>
	</body>
</html>
